-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
support gRPC communication between primary and secondary mantle controllers #32
Conversation
8575c8b
to
6cbd772
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I only reviewed the first commit so far. Please reflect my comments during my remaining reviews.
Makefile
Outdated
@@ -52,7 +69,7 @@ manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and Cust | |||
cat config/rbac/role.yaml | yq '.metadata.name = "mantle-controller"' > charts/mantle-cluster-wide/templates/clusterrole.yaml | |||
|
|||
.PHONY: generate | |||
generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations. | |||
generate: $(PROTOBUF_GEN) controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
generate: $(PROTOBUF_GEN) controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations. | |
generate: $(PROTOBUF_GEN) controller-gen ## Generate boilerplate code. |
Now generate
target generates not only code for CR handling but also gRPC code.
cmd/controller/main.go
Outdated
// nothing to do | ||
case RolePrimary: | ||
if mantleServiceEndpoint == "" { | ||
return errors.New("--mantle-service-endpoint should be specified if --role is 'primary'") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return errors.New("--mantle-service-endpoint should be specified if --role is 'primary'") | |
return errors.New("--mantle-service-endpoint must be specified if --role is 'primary'") |
cmd/controller/main.go
Outdated
} | ||
case RoleSecondary: | ||
if mantleServiceEndpoint == "" { | ||
return errors.New("--mantle-service-endpoint should be specified if --role is 'secondary'") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return errors.New("--mantle-service-endpoint should be specified if --role is 'secondary'") | |
return errors.New("--mantle-service-endpoint must be specified if --role is 'secondary'") |
cmd/controller/main.go
Outdated
managedCephClusterID := os.Getenv("POD_NAMESPACE") | ||
if managedCephClusterID == "" { | ||
setupLog.Error(errors.New("POD_NAMESPACE is empty"), "POD_NAMESPACE is empty") | ||
return errors.New("POD_NAMESPACE is empty") | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code is not necessary since managedCephClusterId
will be initialized in setupReconcilers
.
cmd/controller/main.go
Outdated
|
||
l, err := net.Listen("tcp", mantleServiceEndpoint) | ||
if err != nil { | ||
return fmt.Errorf("failed to listen: %w", err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return fmt.Errorf("failed to listen: %w", err) | |
return fmt.Errorf("failed to listen %s: %w", mantleServiceEndpoint, err) |
return err | ||
} | ||
|
||
var wg sync.WaitGroup |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
var wg sync.WaitGroup | |
var wg sync.WaitGroup | |
wg.Add(1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is my mistake, and I should call wg.Add
every time go
is called. I'll fix my code so.
}() | ||
|
||
go func() { | ||
defer wg.Done() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line is unnecessary since wg.Done()
will be called by L215. If this line exists, wg.Done()
will be called twice and this will result in panic.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is my mistake, and I should call wg.Add
every time go
is called. I'll fix my code so.
cmd/controller/main.go
Outdated
|
||
go func() { | ||
defer wg.Done() | ||
_ = serv.Serve(l) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Checking error and logging is better.
@@ -20,13 +20,15 @@ import ( | |||
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" | |||
|
|||
mantlev1 "github.com/cybozu-go/mantle/api/v1" | |||
"github.com/cybozu-go/mantle/pkg/controller/proto" | |||
) | |||
|
|||
// MantleBackupReconciler reconciles a MantleBackup object | |||
type MantleBackupReconciler struct { | |||
client.Client | |||
Scheme *runtime.Scheme | |||
managedCephClusterID string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about adding role field? Although we can distinguish whether the role is primary by primarySettings
, checking rolle == RolePrimary
is more straightforward.
<-ctx.Done() | ||
serv.GracefulStop() | ||
}() | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you also call setupReconciler()
for the secondary mantle and do nothing in Reconcile()
if the rolle is secondary?
ffe0e5a
to
5e2a32a
Compare
I've fixed my code to resolve your points. |
…ollers This commit allows a mantle-controller to serve as one of standalone, primary, or secondary mode. This commit doesn't have any e2e test's update and it will land on in the following commits. Signed-off-by: Ryotaro Banno <ryotaro.banno@gmail.com>
All of the e2e tests we currently have are written for a single Kubernetes cluster. This commit moves them into a `singlek8s` package. Signed-off-by: Ryotaro Banno <ryotaro.banno@gmail.com>
Signed-off-by: Ryotaro Banno <ryotaro.banno@gmail.com>
5e2a32a
to
cdcc238
Compare
No description provided.